﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Demo.Util
{
    public partial class ThreadInvokerDemo : Form
    {
        public ThreadInvokerDemo()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            progressBar1.Value = 0;
            Cocon90.Lib.Util.ThreadInvoker.CreateInstence().Invoke(() =>
            {
                button1.Enabled = false;
                for (int i = 0; i < 100; i++)
                {
                    lock (progressBar1)
                        progressBar1.Value++;
                    label1.Text = (i + 1) + "%";
                    System.Threading.Thread.Sleep(100);
                }

            }, (finish) =>
            {
                button1.Enabled = true;
                finish.ForEach((thread) =>
                {
                    thread.Abort();//一个一个退出线程
                });
         
                MessageBox.Show("多线程执行完成！");
            });
        }
    }
}
